package com.pf.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 日志输出
 */
@Slf4j
public class LogUtils {

    public static void main(String[] args) {
        try{
            int  i = 1/0;
        }catch (Exception e){
            String stackTrace = getStackTrace(e);
            System.out.println("**************堆栈信息*******************");
            System.out.println(stackTrace);
        }
        
    }

    /**
     * 获取错误堆栈信息
     *
     * @param throwable
     * @return
     */
    public static String getStackTrace(Throwable throwable) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        try {
            throwable.printStackTrace(printWriter);
            return stringWriter.toString();
        } finally {
            printWriter.close();
        }

    }
}
